package com.woniu.p2p.serviceImpl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniu.p2p.entity.UserCharge;
import com.woniu.p2p.mapper.UserChargeMapper;
import com.woniu.p2p.service.P2PChargeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * @author 86152
 * @create 2020/8/8
 * @since 1.0.0
 */
@Service
public class P2PChargeServiceImp implements P2PChargeService {
    @Autowired
    UserChargeMapper userChargeMapper;

    /*查询充值记录*/
    @Override
    public PageInfo<UserCharge> findAllCharge(String s, int start, int size,int userid) {
        PageHelper.startPage(start,size);
        List<UserCharge> userCharges = userChargeMapper.selectAllByUserId(userid);
        for(UserCharge userCharge:userCharges){
            userCharge.setChargeOrder(userCharge.getChargeOrder().substring(0, 8));
        }
        PageInfo<UserCharge> userChargePageInfo = new PageInfo<>(userCharges);
        return userChargePageInfo;
    }

    /*条件查询充值记录*/
    @Override
    public PageInfo<UserCharge> selectChargesByCons(String chargestatus, Date starttime, Date endtime, int start, int size,int userid) {
        PageHelper.startPage(start,size);
        List<UserCharge> userCharges=userChargeMapper.selectChargesByCons(chargestatus,starttime,endtime,userid);
        for(UserCharge userCharge:userCharges){
            userCharge.setChargeOrder(userCharge.getChargeOrder().substring(0, 8));
        }
        PageInfo<UserCharge> userChargePageInfo = new PageInfo<>(userCharges);
        return userChargePageInfo;
    }

    /*删除充值记录通过ID*/
    @Override
    @Transactional
    public PageInfo<UserCharge> deletechargeById(Integer chargeId, String chargestatus, Date starttime, Date endtime, Integer start, int size, int userid) {
        PageHelper.startPage(start,size);
        /*删除充值记录*/
        userChargeMapper.deleteByPrimaryKey(chargeId);
        /*条件查询*/
        List<UserCharge> userCharges=userChargeMapper.selectChargesByCons(chargestatus,starttime,endtime,userid);
        for(UserCharge userCharge:userCharges){
            userCharge.setChargeOrder(userCharge.getChargeOrder().substring(0, 8));
        }
        PageInfo<UserCharge> userChargePageInfo = new PageInfo<>(userCharges);
        return userChargePageInfo;
    }
}
